<template>
	<view class="fui-wrap">
		<fui-list>
			<fui-list-cell v-for="(item,index) in list" :key="index" arrow @click="goDetail(item)">
				<view class="item">
					<view class="line">
						<fui-text text="申请时间：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.createtime" color="black" :size="28"></fui-text>
					</view>
					<view class="line">
						<fui-text text="申请事项：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.plate_number+'，'+type_txt[item.apply_type]" color="black" :size="28"></fui-text>
					</view>
					<view class="line">
						<fui-text text="车主资料：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.contact+'【'+item.mobile+'】'" color="black" :size="28"></fui-text>
					</view>
					<view class="line" v-if="item.pay">
						<fui-text text="支付金额：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="'￥'+parseNumber(item.pay.pay_price)" color="black" :size="28"></fui-text>
					</view>
				</view>
				<view class="status">
					<fui-tag v-if="item.status===0" text="申请中" type="warning"></fui-tag>
					<fui-tag v-if="item.status===1" text="已同意" type="success"></fui-tag>
					<fui-tag v-if="item.status===2" text="已拒绝" type="danger"></fui-tag>
				</view>
			</fui-list-cell>
		</fui-list>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
		<filter :param="param" @confirm="doSubmit"></filter>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {parseNumber} from '@/utils/util.js'
	import filter from '@/components/common/filter.vue';
	export default {
		components:{
			filter:filter
		},
		data() {
			return {
				baseUrl:baseUrl,
				type_txt:{
					month_apply:'申请月卡',
					month_xufee:'过期月卡申请续费',
					day_apply:'申请日卡',
					day_renew:'过期日卡续期',
					stored_apply:'申请储值卡'
				},
				list:[],
				page:1,
				endData:false,
				param:{
					plate_number:'',
					contact:'',
					mobile:''
				}
			}
		},
		onLoad(e) {
			this.getList();
		},
		onShow() {
			let refresh=uni.getStorageSync('refresh') || '';
			if(refresh){
				this.list=[];
				this.page=1;
				this.endData=false;
				uni.setStorageSync('refresh','');
				this.getList();
			}
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.page=1;
			this.endData=false;
			this.getList(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			...methods,
			parseNumber,
			goDetail:function(e){
				this.$navigateTo('parking/cars/applydetail?apply_id='+e.id);
			},
			doSubmit:function(param){
				this.param=param;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			getList:function(callback=false){
				this.showPopup=false;
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				this.$get('parking/cars/apply',{
					...this.param,
					page:this.page
				},true).then(res=>{
					this.list=this.list.concat(res);
					this.page++;
					if(res.length<10){
						this.endData=true;
					}	
					if(callback){
						callback();
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.item{
	display: flex;
	flex-wrap: wrap;
	width: 100%;
	.line{
		display: flex;
		align-items: center;
		width:100%;
		height: 70rpx;	
	}
}
</style>